home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / UIHELPER.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  17KB  |  497 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1994, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_UIHELPER_H)
  10. #define OWL_UIHELPER_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15. #if !defined(OWL_EVENTHAN_H)
  16. # include <owl/eventhan.h>
  17. #endif
  18. #if !defined(WINSYS_WSYSCLS_H)
  19. # include <winsys/wsyscls.h>
  20. #endif
  21. #if !defined(WINSYS_COLOR_H)
  22. # include <winsys/color.h>
  23. #endif
  24.  
  25. #if defined(BI_NAMESPACE)
  26. namespace ClassLib {
  27. #endif
  28.   
  29. class _WSYSCLASS TColor;
  30.  
  31. #if defined(BI_NAMESPACE)
  32. } // namespace ClassLib
  33. #endif
  34.  
  35.   
  36. #if defined(BI_NAMESPACE)
  37. namespace OWL {
  38. #endif
  39.  
  40. // Generic definitions/compiler options (eg. alignment) preceeding the 
  41. // definition of classes
  42. #include <services/preclass.h>
  43.  
  44. class _OWLCLASS  TDC;
  45. class _OWLCLASS  TBrush;
  46. class _OWLCLASS  THatch8x8Brush;
  47. class _OWLCLASS  TBitmap;
  48. class _OWLCLASS  TIcon;
  49.  
  50. //
  51. // Flags of DrawFrameControl API
  52. //
  53. #if !defined(DFC_CAPTION)
  54. # define DFC_CAPTION             1
  55. #endif
  56. #if !defined(DFC_MENU)
  57. # define DFC_MENU                2
  58. #endif
  59. #if !defined(DFC_SCROLL)
  60. # define DFC_SCROLL              3
  61. #endif
  62. #if !defined(DFC_BUTTON)
  63. # define DFC_BUTTON              4
  64. #endif
  65. #if !defined(DFCS_CAPTIONCLOSE)
  66. # define DFCS_CAPTIONCLOSE       0x0000
  67. #endif
  68. #if !defined(DFCS_CAPTIONMIN)
  69. # define DFCS_CAPTIONMIN         0x0001
  70. #endif
  71. #if !defined(DFCS_CAPTIONMAX)
  72. # define DFCS_CAPTIONMAX         0x0002
  73. #endif
  74. #if !defined(DFCS_CAPTIONRESTORE)
  75. # define DFCS_CAPTIONRESTORE     0x0003
  76. #endif
  77. #if !defined(DFCS_CAPTIONHELP)
  78. # define DFCS_CAPTIONHELP        0x0004
  79. #endif
  80. #if !defined(DFCS_MENUARROW)
  81. # define DFCS_MENUARROW          0x0000
  82. #endif
  83. #if !defined(DFCS_MENUCHECK)
  84. # define DFCS_MENUCHECK          0x0001
  85. #endif
  86. #if !defined(DFCS_MENUBULLET)
  87. # define DFCS_MENUBULLET         0x0002
  88. #endif
  89. #if !defined(DFCS_MENUARROWRIGHT)
  90. # define DFCS_MENUARROWRIGHT     0x0004
  91. #endif
  92. #if !defined(DFCS_SCROLLUP)
  93. # define DFCS_SCROLLUP           0x0000
  94. #endif
  95. #if !defined(DFCS_SCROLLDOWN)
  96. # define DFCS_SCROLLDOWN         0x0001
  97. #endif
  98. #if !defined(DFCS_SCROLLLEFT)
  99. # define DFCS_SCROLLLEFT         0x0002
  100. #endif
  101. #if !defined(DFCS_SCROLLRIGHT)
  102. # define DFCS_SCROLLRIGHT        0x0003
  103. #endif
  104. #if !defined(DFCS_SCROLLCOMBOBOX)
  105. # define DFCS_SCROLLCOMBOBOX     0x0005
  106. #endif
  107. #if !defined(DFCS_SCROLLSIZEGRIP)
  108. # define DFCS_SCROLLSIZEGRIP     0x0008
  109. #endif
  110. #if !defined(DFCS_SCROLLSIZEGRIPRIGHT)
  111. # define DFCS_SCROLLSIZEGRIPRIGHT 0x0010
  112. #endif
  113. #if !defined(DFCS_BUTTONCHECK)
  114. # define DFCS_BUTTONCHECK        0x0000
  115. #endif
  116. #if !defined(DFCS_BUTTONRADIOIMAGE)
  117. # define DFCS_BUTTONRADIOIMAGE   0x0001
  118. #endif
  119. #if !defined(DFCS_BUTTONRADIOMASK)
  120. # define DFCS_BUTTONRADIOMASK    0x0002
  121. #endif
  122. #if !defined(DFCS_BUTTONRADIO)
  123. # define DFCS_BUTTONRADIO        0x0004
  124. #endif
  125. #if !defined(DFCS_BUTTON3STATE)
  126. # define DFCS_BUTTON3STATE       0x0008
  127. #endif
  128. #if !defined(DFCS_BUTTONPUSH)
  129. # define DFCS_BUTTONPUSH         0x0010
  130. #endif
  131. #if !defined(DFCS_INACTIVE)
  132. # define DFCS_INACTIVE           0x0100
  133. #endif
  134. #if !defined(DFCS_PUSHED)
  135. # define DFCS_PUSHED             0x0200
  136. #endif
  137. #if !defined(DFCS_CHECKED)
  138. # define DFCS_CHECKED            0x0400
  139. #endif
  140. #if !defined(DFCS_ADJUSTRECT)
  141. # define DFCS_ADJUSTRECT         0x2000
  142. #endif
  143. #if !defined(DFCS_FLAT)
  144. # define DFCS_FLAT               0x4000
  145. #endif
  146. #if !defined(DFCS_MONO)
  147. # define DFCS_MONO               0x8000
  148. #endif
  149.  
  150. //
  151. // class TUIHandle
  152. // ~~~~~ ~~~~~~~~~
  153. // Assists in drawing user manupulators for on-screen objects
  154. //
  155. class _OWLCLASS TUIHandle {
  156.   public:
  157.  
  158.     // Enumeration describing the location of a grapple selection.
  159.     // These constants typically refer to the [mouse] hittest location
  160.     // which caused the grapples to response to a move or resize operation.
  161.     //
  162.     enum TWhere {
  163.       TopLeft     = 0,   // Upper left corner
  164.       TopCenter   = 1,   // Middle of upper edge
  165.       TopRight    = 2,   // Upper right corner
  166.       MidLeft     = 3,   // Middle of left edge
  167.       MidCenter   = 4,   // Somewhere inside the rectangle
  168.       MidRight    = 5,   // Middle of right edge
  169.       BottomLeft  = 6,   // Lower left corner
  170.       BottomCenter= 7,   // Middle of lower edge
  171.       BottomRight = 8,   // Lower right corner
  172.       Outside     =-1,   // Hit completely outside the object
  173.       Inside      =-2    // Hit inside object, not on handles, & InsideSpecial is set
  174.     };
  175.  
  176.     // Enumeration describing the type of grapples to be drawn
  177.     //
  178.     enum TStyle {
  179.       HandlesIn     = 0,    // Handles on the inside of the rectange
  180.       HandlesOut    = 1,    // Handles on the outside of the rectangle
  181.       Framed        = 2,    // Frame rect is drawn solid
  182.       DashFramed    = 4,    // Frame rect is drawn dashed
  183.       Grapples      = 8,    // Eight grapple boxes are drawn
  184.       HatchBorder   = 16,   // Border handle area drawn hatched
  185.       HatchRect     = 32,   // Whole rect drawn hatched
  186.       InsideSpecial = 64,   // Inside area hit-tested independently
  187.     };
  188.     TUIHandle(const TRect& frame,
  189.               uint style = HandlesIn|Grapples|HatchBorder,
  190.               int thickness = 5);
  191.  
  192.     void   MoveTo(int x, int y);
  193.     void   Move(int dx, int dy);
  194.     void   Size(int w, int h);
  195.     TRect  GetBoundingRect() const;
  196.  
  197.     TWhere HitTest(const TPoint& point) const;
  198.     void   Paint(TDC& dc) const;
  199.  
  200.     static uint16 GetCursorId(TWhere where);
  201.  
  202.   private:
  203.     TRect  Frame;
  204.     uint   Style;
  205.     TPoint HandleBox;
  206. };
  207.  
  208. //
  209. // class TUIBorder
  210. // ~~~~~ ~~~~~~~~~
  211. // Assists in drawing borders of many styles.
  212. // Uses win4.0 calls when available
  213. //
  214. class _OWLCLASS TUIBorder {
  215.   public:
  216.     // Constructor flags to limit or modify border
  217.     //
  218.     enum TFlag {
  219.       // Which edge(s) to draw. ctor defaults to all 4
  220.       Left        = 0x0001,
  221.       Top         = 0x0002,
  222.       Right       = 0x0004,
  223.       Bottom      = 0x0008,
  224.       TopLeft     = Top | Left,
  225.       TopRight    = Top | Right,
  226.       BottomLeft  = Bottom | Left,
  227.       BottomRight = Bottom | Right,
  228.       Rect        = Top | Left | Bottom | Right,
  229.  
  230.       Diagonal    = 0x0010,  // Draw diagonal edge (NotAvail intrnl)
  231.       Fill        = 0x0800,  // Fill in middle
  232.       Soft        = 0x1000,  // Soft edge look for buttons
  233.       Adjust      = 0x2000,  // Adjust passed rect to client (Not Applicable)
  234.       Flat        = 0x4000,  // Flat instead of 3d for use in non-3d windows
  235.       Mono        = 0x8000,  // Monochrome
  236.     };
  237.  
  238.     // Enumeration describing hilevel border styles
  239.     //
  240.     enum TStyle {
  241.       None,             //  No border painted at all
  242.       Plain,            //  Plain plain window frame
  243.       Raised,           //  Status field style raised
  244.       Recessed,         //  Status field style recessed
  245.       Embossed,         //  Grouping raised emboss bead
  246.       Grooved,          //  Grouping groove
  247.       ButtonUp,         //  Button in up position
  248.       ButtonDn,         //  Button in down position
  249.       WndRaised,        //  Raised window outer+inner edge
  250.       WndRecessed,      //  Input field & other window recessed
  251.       WellSet,          //  Well option set (auto grows + 1)  
  252.       ButtonUp3x,       //  Button in up position, Win 3.x style
  253.       ButtonDn3x,       //  Button in down position, Win 3.x style
  254.     };
  255.     TUIBorder(const TRect& frame, TStyle style, uint flags = 0);
  256.  
  257.     // Enumeration describing the type of edge to be drawn
  258.     //
  259.     enum TEdge {
  260.       RaisedOuter = 0x01,   // Raised outer edge only
  261.       SunkenOuter = 0x02,   // Sunken outer edge only
  262.       RaisedInner = 0x04,   // Raised inner edge only
  263.       SunkenInner = 0x08,   // Sunken inner edge only
  264.       EdgeOuter =   0x03,   // Mask for outer edge bits
  265.       EdgeInner =   0x0C,   // Mask for inner edge bits
  266.       EdgeRaised =  RaisedOuter | RaisedInner,   // Both inner & outer raised
  267.       EdgeSunken =  SunkenOuter | SunkenInner,   // Both inner & outer sunken
  268.       EdgeEtched =  SunkenOuter | RaisedInner,   // Outer sunken, inner raised
  269.       EdgeBump   =  RaisedOuter | SunkenInner,   // Outer raised, inner sunken
  270.     };
  271.     TUIBorder(const TRect& frame, TEdge edge, uint flags = 0);
  272.  
  273.     void   MoveTo(int x, int y);
  274.     void   Move(int dx, int dy);
  275.     void   Size(int w, int h);
  276.     TRect  GetBoundingRect() const;
  277.     TRect  GetClientRect() const;
  278.  
  279.     void   Paint(TDC& dc) const;
  280.  
  281.     // Wrapper / Emulation of Win4.0 API call
  282.     //
  283.     static bool DrawEdge(TDC& dc, const TRect& frame, uint edge, uint flags);
  284.  
  285.     // Paint a 2-color frame. With and w/o bevel corner color specified
  286.     //
  287.     static void PaintFrame(TDC& dc, const TRect& frame, uint flags,
  288.                            const TColor& tlColor, const TColor& brColor);
  289.     static void PaintFrameC(TDC& dc, const TRect& frame, uint flags,
  290.                             const TColor& tlColor, const TColor& brColor,
  291.                             const TColor& bcColor);
  292.  
  293.     // Paint a custom frame
  294.     //
  295. //    static void PaintWT(TDC& dc, const TRect& frame);  // WindowText color
  296. //    static void Paint3H(TDC& dc, const TRect& frame);  // 3dHighlight color
  297.  
  298.   protected:
  299.   private:
  300.     TRect  Frame;
  301. //    uint   Style;
  302.     uint   Edge;
  303.     uint   Flags;
  304. };
  305.  
  306. //
  307. // class TUIFace
  308. // ~~~~~ ~~~~~~~
  309. // Assists in painting UI elements in various states.
  310. //
  311. class _OWLCLASS TUIFace {
  312.   public:
  313.  
  314.     // Enumeration describing the state of the bitmap to be drawn
  315.     //
  316.     enum TState {
  317.       Normal,     // Normal state
  318.       Down,       // Down or Option set state (hilit background, +1,+1)
  319.       Indeterm,   // Indeterminant, or mixed-value state
  320.       Disabled,   // Disabled or Unavailable state (embossed 3d no color)
  321.       Default,    // Default btn state (bold)
  322.     };
  323.  
  324.     TUIFace(const TRect& faceRect, const TBitmap& bm,
  325.             const TColor& bgndColor = TColor::White, 
  326.             const TColor& fillColor = TColor::Sys3dFace);
  327.     TUIFace(const TRect& faceRect, const char far* text,
  328.             const TColor& fillColor = TColor::Sys3dFace);
  329.     TUIFace(const TRect& faceRect, const TIcon& icon,
  330.             const TColor& bgndColor = TColor::White, 
  331.             const TColor& fillColor = TColor::Sys3dFace);
  332.  
  333.     void  Paint(TDC& dc, const TPoint& dstPt, TState state, bool pressed,
  334.                 bool fillFace = true);
  335.     void  Paint(TDC& dc, const TRect& srcRect, const TPoint& dstPt,
  336.                 TState state, bool pressed, bool fillFace = true);
  337.     void  PaintMask(TDC& dc, const TPoint& pt);
  338.  
  339.     // Wrapper / Emulation of Win4.0 API call [::DrawState]
  340.     //
  341.     static bool Draw(TDC& dc, HBRUSH hbr, LPARAM lp, WPARAM wp,
  342.                      int x, int y, int cx, int cy, uint flags);
  343.  
  344.     // Internal static helper functions that can be used alone
  345.     //
  346.     static void   PaintBm(const TBitmap& glyph, const TRect& glyphSrcRect,
  347.                           TDC& dc, const TRect& faceRect, const TPoint& dstPt,
  348.                           TState state, bool pressed, bool fillFace,
  349.                           const TColor& maskColor, const TColor& fillColor);
  350.     static void   PaintText(const char far* text, TDC& dc, const TRect& faceRect,
  351.                             const TPoint& dstPt, TState state, bool fill);
  352.  
  353.     static void   PaintMaskBm(const TBitmap& glyph, TDC& dc, const TPoint& pt,
  354.                               const TColor& maskColor);
  355.  
  356.     static void   BuildMask(TDC& maskDC, const TPoint& maskDst, const TSize& maskSize,
  357.                             TDC& glyphDC, const TRect& glyphRect,
  358.                             const TColor& maskColor);
  359.     static void   FillBackground(TDC& dc, TDC& maskDC,
  360.                                  const TRect& dstRect, const TBrush& brush);
  361.     static void   DitherBackground(TDC& dc, TDC& maskDC, const TRect& dstRect);
  362.     static int    DrawTextEtched(TDC& dc, const char far* str, int count,
  363.                                  const TRect& rect, uint16 format);
  364.  
  365.     static THatch8x8Brush& GetDitherBrush();
  366.     static TBitmap&        GetGlyphMask(const TSize& minSize);
  367.  
  368.   private:
  369.     const TRect     Rect;
  370.     const char far* Text;
  371.     const TBitmap*  Bm;
  372.     const TIcon*    Icon;
  373.     const TColor    BkgndColor;
  374.     const TColor    FillColor;
  375. };
  376.  
  377.  
  378. //
  379. // class TUIPart
  380. // ~~~~~ ~~~~~~~
  381. // Encapsulates the DrawFrameControl 32-bit API.
  382. //
  383. class _OWLCLASS TUIPart {
  384.   public:
  385.  
  386.     // Enumeration describing the part to be drawn.
  387.     // NOTE: TType describes the part, TState then refines the exact
  388.     //       glyph of the selected part.
  389.     //
  390.     enum  TType {
  391.       uiButton  = DFC_BUTTON,     // Draw a button glyph
  392.       uiCaption = DFC_CAPTION,    // Draw a caption glyph
  393.       uiMenu    = DFC_MENU,       // Draw a menu glyph
  394.       uiScroll  = DFC_SCROLL      // Draw a scroll bar glyph
  395.     };
  396.  
  397.     // Enumeration describing the various glyphs available for buttons,
  398.     // captions, menus and scrollbar parts.
  399.     //
  400.     enum  TState {
  401.       Button3State      = DFCS_BUTTON3STATE,     // Three-state button
  402.       ButtonCheck       = DFCS_BUTTONCHECK,      // Check box
  403.       ButtonPush        = DFCS_BUTTONPUSH,       // Push button
  404.       ButtonRadio       = DFCS_BUTTONRADIO,      // Radio button
  405.       ButtonRadioImage  = DFCS_BUTTONRADIOIMAGE, // Image for radio button (nonsquare needs image)
  406.       ButtonRadioMask   = DFCS_BUTTONRADIOMASK,  // Mask for radio button (nonsquare needs mask)
  407.       Checked           = DFCS_CHECKED,          // Draw button as checked
  408.       Flat              = DFCS_FLAT,             // Draw button with flat border
  409.       Inactive          = DFCS_INACTIVE,         // Draw button grayed
  410.       Mono              = DFCS_MONO,             // Draw button with monochrome border
  411.       Pushed            = DFCS_PUSHED,           // Draw button pushed
  412.       CaptionClose      = DFCS_CAPTIONCLOSE,     // Close button
  413.       CaptionHelp       = DFCS_CAPTIONHELP,      // Help button
  414.       CaptionMax        = DFCS_CAPTIONMAX,       // Maximize button
  415.       CaptionMin        = DFCS_CAPTIONMIN,       // Minimize button
  416.       CaptionRestore    = DFCS_CAPTIONRESTORE,   // Restore button
  417.       MenuArrow         = DFCS_MENUARROW,        // Submenu arrow
  418.       MenuBullet        = DFCS_MENUBULLET,       // Bullet
  419.       MenuCheck         = DFCS_MENUCHECK,        // Check mark
  420.       ScrollCombo       = DFCS_SCROLLCOMBOBOX,   // Combo box scroll bar
  421.       ScrollDown        = DFCS_SCROLLDOWN,       // Down arrow of scroll bar
  422.       ScrollLeft        = DFCS_SCROLLLEFT,       // Left arrow of scroll bar
  423.       ScrollRight       = DFCS_SCROLLRIGHT,      // Right arrow of scroll bar
  424.       ScrollSizeGrip    = DFCS_SCROLLSIZEGRIP,   // Size grip in bottom-right corner of window
  425.       ScrollUp          = DFCS_SCROLLUP          // Up arrow of scroll bar
  426.     };
  427.  
  428.     TUIPart();
  429.     bool Paint(TDC& dc, TRect& rect, TType type, TState state);
  430.     bool DrawFrameControl(TDC& dc, TRect& rect, TType type, TState state);
  431.  
  432.   protected:
  433. };
  434.  
  435.  
  436. //
  437. // class TUIHelper
  438. // ~~~~~ ~~~~~~~~~
  439. // Wrapper for misc. Win4 USER functions.
  440. //
  441. class _OWLCLASS TUIHelper {
  442.   public:
  443.     static HANDLE LoadImage(HINSTANCE hI, const char far*, uint, int, int, uint);
  444.     static bool DrawState(HDC, HBRUSH, DRAWSTATEPROC, TParam2, TParam1, int, int, int, int, UINT);
  445. };
  446.  
  447. // Generic definitions/compiler options (eg. alignment) following the 
  448. // definition of classes
  449. #include <services/posclass.h>
  450.  
  451. #if defined(BI_NAMESPACE)
  452. } // namespace OWL
  453. #endif
  454.  
  455. //----------------------------------------------------------------------------
  456. // Inline implementations
  457. //
  458.  
  459. //
  460. // Initialize the button face with a bitmap.
  461. //
  462. inline
  463. TUIFace::TUIFace(const TRect& faceRect, const TBitmap& bm,
  464.                  const TColor& bkgndColor, const TColor& fillColor)
  465. :
  466.   Rect(faceRect), Bm(&bm), Text(0), Icon(0),
  467.   BkgndColor(bkgndColor), FillColor(fillColor)
  468. {
  469. }
  470.  
  471. //
  472. // Initialize the button face with a text string.
  473. //
  474. inline
  475. TUIFace::TUIFace(const TRect& faceRect, const char far* text,
  476.                  const TColor& fillColor)
  477. :
  478.   Rect(faceRect), Bm(0), Text(text), Icon(0),
  479.   BkgndColor(TColor::None), FillColor(fillColor)
  480. {
  481. }
  482.  
  483. //
  484. // Initialize the button face with an icon.
  485. //
  486. inline
  487. TUIFace::TUIFace(const TRect& faceRect, const TIcon& icon,
  488.                  const TColor& bkgndColor, const TColor& fillColor)
  489. :
  490.   Rect(faceRect), Bm(0), Text(0), Icon(&icon),
  491.   BkgndColor(TColor::None), FillColor(fillColor)
  492. {
  493. }
  494.  
  495. #endif  // OWL_UIHELPER_H
  496.  
  497.